<div class="modal-header">
	<h5 class="modal-title mt-0" id="exampleModalLabel">{$vo['id'] ? '编辑CPN' : '增加CPN'}</h5>
	<button type="button" class="close" data-dismiss="modal" aria-label="Close">
	  <span aria-hidden="true">&times;</span>
	</button>
  </div>
  <div class="modal-body">
	<div class="form-group row">
		<label for="example-text-input" class="col-sm-4 col-form-label text-right">CPN编号</label>
		<div class="col-sm-8">
			<input class="form-control" type="text" id="cpn_sn" name="cpn_sn" value="{$vo.cpn_sn}" maxlength="8" data-toggle="tooltip" data-placement="top" title="最长8个字符">
		</div>
	</div>
	<div class="form-group row">
		<label for="example-text-input" class="col-sm-4 col-form-label text-right">被控设备编号</label>
		<div class="col-sm-8">
			<input class="form-control" type="text" id="device_sn" name="device_sn" value="{$vo.device_sn}">
		</div>
	</div>
	<div class="form-group row">
		<label for="example-text-input" class="col-sm-4 col-form-label text-right">安装楼层</label>
		<div class="col-sm-8">
			<select class="form-control" id="floor" name="floor">
				<option value="">请选择</option>
				<foreach name="floors" item="voo">
					<option value="{$key}" {$vo['floor']==$key ? 'selected' : ''}>{$voo}</option>
				</foreach>
			</select>
		</div>
	</div>
	<div class="form-group row">
		<label class="col-sm-4 col-form-label text-right">机电系统类型</label>
		<div class="col-sm-8">
			<select class="form-control" id="sys_type" name="sys_type" onchange="changeType()">
				<option value="">请选择</option>
				<foreach name="sys_codes" item="voo">
					<option value="{$key}" {$vo['sys_type']==$key ? 'selected' : ''}>{$voo}</option>
				</foreach>
			</select>
		</div>
	</div>
	<div class="form-group row">
		<label class="col-sm-4 col-form-label text-right">专用控制器类型</label>
		<div class="col-sm-8">
			<select class="form-control" id="group_code" name="group_code">
				<option value="">请选择</option>
				<foreach name="group_codes" item="voo">
					<option value="{$key}" <php>echo $vo['cpn_type'].','.$vo['group_code']==$key ? 'selected' : '';</php>>{$voo}</option>
				</foreach>
			</select>
		</div>
	</div>
	<div class="form-group row">
		<label for="intro" class="col-sm-4 col-form-label text-right">备注描述</label>
		<div class="col-sm-8">
			<textarea class="form-control" id="intro" name="intro" rows="3">{$vo.intro}</textarea>
		</div>
	</div>
  </div>
  <div class="modal-footer">
	<input type="hidden" name="project_id" value="{$Think.request.project_id}" />
	<input type="hidden" name="act" value="{$vo['id'] ? 'edit' : 'add'}" />
	<input type="hidden" name="id" value="{$vo.id}" />
	<button type="button" class="btn btn-info px-4 align-self-center add-btn" onclick="chk(this);">{$vo['id'] ? '立即保存' : '立即添加'}</button>
</div>
<script>
function changeType(){
	var sys_code = $('#sys_type').val();
	var url = "{:U('getGroupCode')}";
	var html = '<option value="">请选择</option>';

	$.getJSON(url, {sys_code: sys_code}, function(res){
		if(res){
			for(var k in res){
				html += '<option value="' + k + '">' + res[k] + '</option>';
			}
		}
		$('#group_code').html(html);
	});
}

function chk(obj){
	var floor = $('#floor').val();
	<empty name="floors">
		notify('error', '提示', '还没有设置楼层，请先设置！');
		//$('#floortip').tooltip('show');
		return;
	</empty>
	if(floor == ''){
		notify('error', '提示', '请选择楼层！');
		$('#floor').focus();
		return;
	}
	obj.form.submit();
}
</script>